/*
 * Copyright (c) 2015, the Dart project authors.
 *
 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package vm.element

// This file is generated by the script: pkg/vm_service/tool/generate.dart in dart-lang/sdk.

import com.google.gson.JsonObject

/**
 * {@link BoundVariable} 表示绑定到 {@link Frame} 中特定值的局部变量。
 */
class BoundVariable(json: JsonObject) : Response(json) {

    /**
     * 绑定变量的名称。
     */
    /**
     * 绑定变量的名称。
     */
    fun getName(): String {
        return getAsString("name")!!
    }

    /**
     * 此变量对作用域可见的最后一个令牌位置。
     */
    fun getScopeEndTokenPos(): Int {
        return getAsInt("scopeEndTokenPos")
    }

    /**
     * 此变量对作用域可见的第一个令牌位置。
     */
    fun getScopeStartTokenPos(): Int {
        return getAsInt("scopeStartTokenPos")
    }

    /**
     * @return <code>InstanceRef</code>、<code>TypeArgumentsRef</code> 或
     * <code>Sentinel</code> 之一
     */
    fun getValue(): Any? {
        val elem = json.get("value")
        if (elem == null) return null

        if (elem.isJsonObject) {
            val o = elem.asJsonObject
            when (o.get("type").asString) {
                "@Instance" -> return InstanceRef(o)
                "@TypeArguments" -> return TypeArgumentsRef(o)
                "Sentinel" -> return Sentinel(o)
            }
        }
        return null
    }
}
